package com.solo.config;

import com.solo.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*
 * FileName: WebConfig.java
 * Description: //模块目的、功能描述
 * Author:   woolflighthouse@163.com
 * Date:     2025-11-23 22:11
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册登录拦截器并配置拦截路径
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/", "/home", "/admin/**") // 添加根路径拦截
                .excludePathPatterns("/login", "/logout", "/css/**", "/js/**", "/images/**");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 设置根路径重定向到登录页
        registry.addViewController("/").setViewName("redirect:/login");
    }
}
